'''
   author:黎作文
   date:2021/11/23 17:42
   project:11.23模块与包&异常处理.py
'''
# 作业一代码
# import random,string
# N=int(input("请输入激活码的个数："))
# for i in range(N):
#     ran_str = ''.join(random.sample(string.ascii_uppercase + string.digits, 32))
#     with open("code.txt","a+") as f:
#         f.write(ran_str + "\n")
#         f.read()
#     print (ran_str)

# from setuptools import setup,find_packages
# setup(
#         #包名
#      name = "code",
#      #官网
#         url = "http://www.sanchuangedu.cn",
#      #版本号
#      version = "0.0.1",
#      #指定要打包的模块和包
#      packages = find_packages(),
#      #作者
#      author = "lizuowen",
#      #邮箱
#      author_email = "2262493150@qq.com",
#      #依赖
#      install_requires = ['xlrd>=1.1.0'],
#      #描述信息
#      description = "this is test package"
#      )

# 作业二代码
try:
    import IPy
    import subprocess
    ips=IPy.IP("192.168.233.0/24")
    for ip in ips:
        # print(ip)
        result=subprocess.call(f"ping -c 1 {ip}", shell=True)
        print(result)
        # c=subprocess.Popen(["echo &?"])
        if result == 0:
            with open("ip.txt", "a+", encoding="utf-8") as fp:
                fp.write(f"{ip}已被使用\n")
        if result == 1:
            with open("ip2.txt", "a+", encoding="utf-8") as fp1:
                fp1.write(f"{ip}未被使用\n")
except ValueError:
    print("输入不合法")
except Exception:
    print("other False")
